package com.ctgu.springboot.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ctgu.springboot.common.QueryPageParam;
import com.ctgu.springboot.entity.Teacher;
import com.ctgu.springboot.mapper.TeacherMapper;
import com.ctgu.springboot.service.TeacherService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author wms
 * @since 2023-02-16
 */
@Service
public class TeacherServiceImpl extends ServiceImpl<TeacherMapper, Teacher> implements TeacherService {

    @Resource
    private TeacherMapper teacherMapper;

    @Override
    public IPage<Teacher> teacherPage(QueryPageParam query) {

        Integer id = (Integer) query.getParam().get("tea_id");
        String name = (String) query.getParam().get("tea_name");
        Integer schoolId = (Integer) query.getParam().get("sc_id");
        Integer comId = (Integer) query.getParam().get("com_id");
        String phone = (String) query.getParam().get("tea_phone");

        Page<Teacher> page = new Page<>();
        page.setCurrent(query.getPageNum());
        page.setSize(query.getPageSize());

        LambdaQueryWrapper<Teacher> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        if (id!=null) {
            lambdaQueryWrapper.like(Teacher::getTeaId, id);
        }
        if (comId!=null) {
            lambdaQueryWrapper.like(Teacher::getComId, comId);
        }
        if (StringUtils.isNotBlank(name) && !"null".equals(name)) {
            lambdaQueryWrapper.like(Teacher::getTeaName, name);
        }
        if (schoolId!=null) {
            lambdaQueryWrapper.eq(Teacher::getScId, schoolId);
        }
        if (StringUtils.isNotBlank(phone) && !"null".equals(phone)) {
            lambdaQueryWrapper.eq(Teacher::getTeaPhone, phone);
        }
        return teacherMapper.teacherPage(page, lambdaQueryWrapper);
    }

    @Override
    public List<Teacher> getList(){
        return teacherMapper.getList();
    }
}
